package com.ixuestar.util;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;

import com.alibaba.fastjson.JSON;


public class MessageUtil {

    public static final String charset = "utf-8";
    // 用户平台API账号(非登录账号,示例:N1234567)
    public static String account = "N3515245";
    // 用户平台API密码(非登录密码)
    public static String password = "BPCFNAwITZ23e7";

    public static void sendMessage(String ixsName,String ixsgName,String ixscName,String ixstName,String ymaMsg,String ywTelephone,String mobile) throws UnsupportedEncodingException {
        //请求地址请登录253云通讯自助通平台查看或者询问您的商务负责人获取
        String smsSingleRequestServerUrl = "http://smssh1.253.com/msg/send/json";
        // 短信内容
        String msg = "【云易学教师端】"+ixsName+ixsgName+ixscName+ixstName+"老师出现"+ymaMsg+"错误，电话："+ywTelephone;
        //手机号码
//        String phone = "159********";
        //状态报告
        String report= "true";

        SmsSendRequest smsSingleRequest = new SmsSendRequest(account, password, msg, mobile,report);

        String requestJson = JSON.toJSONString(smsSingleRequest);

        System.out.println("before request string is: " + requestJson);

        String response = ChuangLanSmsUtil.sendSmsByPost(smsSingleRequestServerUrl, requestJson);

        System.out.println("response after request result is :" + response);

        SmsSendResponse smsSingleResponse = JSON.parseObject(response, SmsSendResponse.class);

        System.out.println("response  toString is :" + smsSingleResponse);
    }
	
	/**
	 * 验证码发送
	 * @param code
	 * @param mobile
	 */
	public static void getVerificationCode(String ixsName,String ixsgName,String ixscName,String ixstName,String ymaMsg,String ywTelephone,String mobile) {
		String host = "https://cxkjsms.market.alicloudapi.com";
		String path = "/chuangxinsms/dxjk";
		String method = "POST";
		String appcode = "64b41e45e09b425ebf3de20a8450ab13";
		Map<String, String> headers = new HashMap<String, String>();
		//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
		headers.put("Authorization", "APPCODE " + appcode);
		Map<String, String> querys = new HashMap<String, String>();
		//	    querys.put("Template", "短信模板中签名和内容自定义，请联系旺旺客服或qq：726980650报备。");
		querys.put("content", "【云易学】"+ixsName+ixsgName+ixscName+ixstName+"老师"+ymaMsg+"，电话"+ywTelephone);
		querys.put("mobile", mobile);
		Map<String, String> bodys = new HashMap<String, String>();


		try {
			/**
			 * 重要提示如下:
			 * HttpUtils请从
			 * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
			 * 下载
			 *
			 * 相应的依赖请参照
			 * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
			 */
			HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
			System.out.println(response.toString());
			//获取response的body
			//System.out.println(EntityUtils.toString(response.getEntity()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
